<#assign module="sys"/>

<@override name="header">
</@override>
<@override name="body">

	<div class="row">
		<div class="col-md-12">
			<div class="panel panel-default">
				<div class="panel-heading">
					填写用户信息
			    </div>
			    <div class="panel-body">
    				<form id="submit_form" action="${ctx}/admin/update" class="form-horizontal" method="post">
		               	<input type="hidden" name="id" value="${admin.id}">
		                <div class="form-group">
		                    <label class="col-sm-3 control-label"><em>*</em>用户名：</label>
		                    <div class="col-sm-3">
		                    	<p class="form-control-static">
		                    	${admin.username?if_exists}
		                    	</p>
		                    </div>
		                </div>
		                
		                <div class="form-group">
		                    <label class="col-sm-3 control-label"><em>*</em>密码：</label>
		                    <div class="col-sm-3">
		                    	<input class="form-control" id="password" name="password" type="password" placeholder="如不修改密码，此项留空"/>
		                    </div>
		                </div>
		                
		                <div class="form-group">
		                    <label class="col-sm-3 control-label"><em>*</em>重复密码：</label>
		                    <div class="col-sm-3">
		                    	<input class="form-control" id="passwordconfirm" name="passwordconfirm" type="password" placeholder="如不修改密码，此项留空"/>
		                    </div>
		                </div>
		                <@shiro.isMainCompany>
							<div class="form-group">
								<label class="col-sm-3 control-label"><em>*</em>所属公司：</label>
								<div class="col-sm-3">
									<select class="form-control" id="companyid" name="companyid" required>
										<#list companys as company>
											<option value="${company.id}" <#if admin.companyId==company.id>selected="selected"</#if>>${company.companyName}</option>
										</#list>
									</select>
								</div>
							</div>
						</@shiro.isMainCompany>
		                
		                <div class="form-group">
		                    <label class="col-sm-3 control-label">手机号码：</label>
		                    <div class="col-sm-3">
		                    	<input class="form-control" id="phone" name="phone" type="text" value="${admin.phone?if_exists}" placeholder="用于短信登录收取验证码"/>
		                    </div>
		                    <div class="col-sm-3 checkbox">
							    <label>
							      <input type="checkbox" id="phoneLogin" name="phoneLogin" <#if admin.phoneLogin??>${admin.phoneLogin?string('checked="checked"','')}</#if>> 开启短信登录
							    </label>
						  	</div>
		                </div>
		                
		                <div class="form-group">
                            <label class="col-sm-3 control-label">是否锁定：</label>
                            <div class="col-sm-7">
                                <label>
                                	<p class="form-control-static">
								  		<#if admin.isLocked>
								  			<span style="color:#EA0000;font-weight:700;">已锁定</span>
								  		<#else>
								  			<span style="font-weight:700;">正常</span>
								  		</#if>
									</p>
								</label>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label"><em>*</em>角色选择：</label>
                            <div class="col-sm-7">
                            	<#list roles as role>
									<label style="padding-right:12px;">
										<p class="form-control-static">
									  		<input type="checkbox" value="${role.id}" name="roleIds" <#if admin.roles?seq_contains(role)> checked="checked"</#if>/> ${role.name}
										</p>
									</label>
								</#list>
                            </div>
                        </div>
    					
		                <div class="form-group" style="margin-left:10px;">
			                <label class="col-sm-3 control-label"></label>
			                <input type="submit" class="btn btn-primary" value="保存">
			                <input type="button" class="btn btn-default" onclick="window.location.href = '${ctx}/admin/list';" value="返回">
			            </div>
					</form>
        		</div>
			</div>
		</div>
	</div>

</@override>
<@override name="footer">
<script src="${ctx}/assets/js/md5.js"></script>
<script src="${ctx}/assets/js/base64.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$("#submit_form").submit(function(){
		
		var password=$.trim($("#password").val());
		if(password!=''){
			if(password.length<8 || password.length>30){
				$.scojs_message("密码长度为8到30个字符。", $.scojs_message.TYPE_ERROR);
				return false;
			}
			
			var password_regex = new RegExp('(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{8,30}');
			if(!password_regex.test(password)){
				$.scojs_message("密码格式不正确，采用数字、字母、特殊字符三种组合", $.scojs_message.TYPE_ERROR);
				return false;
			}
			
			var passwordconfirm=$.trim($("#passwordconfirm").val());
			if(password!=passwordconfirm){
				$.scojs_message("密码不一致", $.scojs_message.TYPE_ERROR);
				return false;
			}
		}
		
		if($("#phoneLogin").is(':checked')){
			if($("#phone").val().trim()==""){
				$.scojs_message("开启短信登录后需要填写手机号码", $.scojs_message.TYPE_ERROR);
				return false;
			}
		}
			
		if($("input[name=roleIds]:checked").length==0){
			$.scojs_message("至少选择一个角色", $.scojs_message.TYPE_ERROR);
			return false;
		}
		if(!$("#companyid").val()){
			$.scojs_message("请选择所属公司", $.scojs_message.TYPE_ERROR);
			return false;
		}
		
		if(password!=''){
			$("#password").val(new Base64().encode($.md5($("#password").val())));
		}
        if(passwordconfirm!=''){
            $("#passwordconfirm").val(new Base64().encode($.md5($("#passwordconfirm").val())));
        }
		return true;
	});
});
</script>
</@override>
<@extends name="../layout.ftl"/>
